package GUI;

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JPasswordField;
import java.awt.Font;
import java.awt.Color;
import java.io.IOException;
import javax.swing.UIManager;

public class Login_GUI extends JPanel {
	private JTextField UserTextField;
	private JTextField PassTextField;
	private final Client_GUI parent;
	
	public Login_GUI(final Client_GUI parent) {
		this.setBackground(UIManager.getColor("inactiveCaption"));

		this.parent = parent;
		
		setLayout(null);
		
		JLabel lblNewLabel = new JLabel("Username:");
		lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 13));
		lblNewLabel.setBounds(265, 113, 90, 21);
		add(lblNewLabel);
		
		JLabel lblPassword = new JLabel("Password:");
		lblPassword.setFont(new Font("Tahoma", Font.BOLD, 13));
		lblPassword.setBounds(265, 168, 90, 14);
		add(lblPassword);
		
		UserTextField = new JTextField();
		UserTextField.setBounds(354, 114, 167, 20);
		add(UserTextField);
		UserTextField.setColumns(10);
		
		PassTextField = new JTextField();
		PassTextField.setBounds(356, 166, 165, 20);
		add(PassTextField);
		PassTextField.setColumns(10);
		
		JButton btnLogin = new JButton("Login");
		btnLogin.setFont(new Font("Tahoma", Font.BOLD, 11));
		btnLogin.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				//parent.setHostIP(ipText.getText());
				//TODO fix to dynamic!!!
				
				//TODO verify UID is only string + change UserName to UID
				
				//parent.setHostIP("localhost");
				parent.Login(UserTextField.getText(), PassTextField.getText(),true);
				
			}
		});
		btnLogin.setBounds(335, 235, 90, 23);
		add(btnLogin);
		
		JButton btnCancel = new JButton("Cancel");
		btnCancel.setFont(new Font("Tahoma", Font.BOLD, 11));
		btnCancel.setBounds(450, 235, 90, 23);
		add(btnCancel);
		
		JLabel lblLogin = new JLabel("Login ");
		lblLogin.setForeground(Color.RED);
		lblLogin.setFont(new Font("Tahoma", Font.BOLD, 19));
		lblLogin.setBounds(408, 48, 114, 39);
		add(lblLogin);
		
		this.setVisible(true);
	}
}
